﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using ShoppingOnline.Data;
using Microsoft.Extensions.DependencyInjection;

namespace ShoppingOnline.Service
{
    public class ServiceDbcontext
    {
        private IServiceProvider _serviceprovider;
        public ServiceDbcontext(IServiceProvider serviceprovider)
        {
            _serviceprovider = serviceprovider;
        }

        private DbContext _dbcontext;
        public DbContext DbContext
        {
            get
            {
                if (_dbcontext == null)
                {
                    _dbcontext = _serviceprovider.GetService<MyDbcontext>();
                }
                return _dbcontext;
            }
        }
    }
}
